﻿using Management.API.Application.Controller.Management;
using Management.API.Application.Controller.Management.Material;
using Management.API.DTOs.Management;
using Management.Errorcode;
using Management.Models.BOMBasicInformation;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;



namespace Management.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MaterialController : ControllerBase
    {
        private readonly ILogger<MaterialController> _logger;
        private readonly IMediator _mediator;
        public MaterialController(ILogger<MaterialController> logger, IMediator mediator)
        {
            _logger = logger;
            _mediator = mediator;
        }


        /// <summary>
        /// 获取物料类型信息
        /// </summary>
        /// <returns>所有物料类型信息</returns>
        [HttpGet]
        public async Task<ApiResult<IList<GetMaterialTypeDTO>>> GetAllMaterialTypes([FromQuery] GetMaterialTypeCommand query)
        {
            //   创建一个没有查询条件的查询对象
            //   var query = new GetMaterialTypeCommand();
            return await _mediator.Send(query);
        }

        /// <summary>
        /// 获取物料属性信息
        /// </summary>    
        /// <returns>所有物料属性信息</returns>
        [HttpGet]
        public async Task<ApiResult> GetAllMaterialProperties([FromQuery] GetMaterialPropertyCommand query)
        {
            //  创建一个没有查询条件的查询对象
            //  var query = new GetMaterialPropertyCommand();
            return await _mediator.Send(query);
        }

        /// <summary>
        /// 获取物料分类信息
        /// </summary>
        /// <returns>所有物料分类信息</returns>
        [HttpGet]
        public async Task<ApiResult> GetAllMaterialCategories([FromQuery] GetMaterialClassificationCommand query)
        {
            // 创建一个没有查询条件的查询对象
            // var query = new GetMaterialClassificationCommand();
            return await _mediator.Send(query);
        }

        /// <summary>
        /// 获取物料信息
        /// </summary> 
        /// <param name="query">获取物料的请求查询</param>
        /// <returns>物料信息</returns>
        [HttpGet]
        public async Task<ApiResult> GetMaterial([FromQuery] GetMaterialCommand query)
        {
            return await _mediator.Send(query);
        }

        /// <summary>
        /// 添加物料信息
        /// </summary>
        /// <param name="command">添加物料的请求命令</param>
        /// <returns>操作结果</returns>
        [HttpPost]
        public async Task<ApiResult> AddMaterial([FromBody] AddMaterialCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 删除物料信息
        /// </summary>
        /// <param name="command">删除物料的请求命令</param>
        /// <returns>操作结果</returns>
        [HttpPost]
        public async Task<ApiResult> DeleteMaterial([FromBody] DeleteMaterialCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 根据物料ID获取物料信息  
        /// </summary>
        /// <param name="materialId">物料的唯一标识符</param>
        /// <returns>物料信息</returns> GetMaterialByIdQuery
        [HttpGet]
        public async Task<ApiResult> GetMaterialById(int materialId)
        {
            var query = new GetMaterialCommand { MaterialId = materialId };
            return await _mediator.Send(query);
        }

        /// <summary>
        /// 修改物料信息
        /// </summary>
        /// <param name="command">修改物料的请求命令</param>
        /// <returns>操作结果</returns>
        [HttpPost]
        public async Task<ApiResult> UpdateMaterial([FromBody] UpdateMaterialCommand command)
        {
            return await _mediator.Send(command);
        }




    }
}
